package com.gin.kotlin.no_gay_alliance.fragment.replyhistory

import com.gin.kotlin.no_gay_alliance.R
import com.gin.kotlin.no_gay_alliance.adapter.replyhistory.ReplyHistoryTaskAdapter
import com.gin.kotlin.no_gay_alliance.app.App
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingRecyclerViewAdapter
import com.gin.kotlin.no_gay_alliance.worker.ReplyHistoryTaskScannerWorker.Companion.DELAY_SECONDS

class ReplyHistoryConfigTaskFragment : AbstractReplyHistoryConfigFragment() {
    private lateinit var adapter: ReplyHistoryTaskAdapter
    override fun obtainFunctionDescription() = R.string.reply_history_function_info_task

    override fun query() {
        // 取消原本的延迟自动刷新
        handler?.removeCallbacks(autoRefresh)

        App.INSTANCE.database.replyHistoryTaskDao().list()?.also {
            adapter.replaceData(it)
            b?.swipeRefreshLayout?.isRefreshing = false
        }
        // 设置延迟自动刷新
        uiDelayed(DELAY_SECONDS * 1000, autoRefresh)
    }

    override fun showAddDialog() {
        handler?.toastDevInProgress()
    }

    override fun obtainAdapter(): AbstractBindingRecyclerViewAdapter<*, *> {
        this.adapter = ReplyHistoryTaskAdapter(requireContext(), handler!!)
        return adapter
    }
}